#if UNITY_EDITOR
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using UnityEditor;
using UnityEngine;
using Debug = UnityEngine.Debug;
public class Editor_ExtendUtils
{
    public class DeleteData
    {
        [MenuItem(Editor_Scene.cTools + "/删除数据/所有缓存数据", false, 0)]
        public static void DeleteTempDataAll()
        {
            PlayerPrefs.DeleteAll();
            Directory.Delete(Application.persistentDataPath, true);
            Directory.Delete(Application.temporaryCachePath, true);
//            var userDataDir = CBaseInfo.userDataDir;
//            if(Directory.Exists(userDataDir))
//            {
//                Directory.Delete(userDataDir, true);
//            }
        }

        [MenuItem(Editor_Scene.cTools + "/删除数据/(01) 沙盒 persistentDataPath", false, 10)]
        public static void DeletePersistentDataPath()
        {
            Directory.Delete(Application.persistentDataPath, true);
        }

        [MenuItem(Editor_Scene.cTools + "/删除数据/(02) PlayerPrefs", false, 15)]
        public static void DeletePlayerPrefs()
        {
            PlayerPrefs.DeleteAll();
        }

        [MenuItem(Editor_Scene.cTools + "/删除数据/(03) 缓存 temporaryCachePath", false, 15)]
        static void OpenPersistentPathss()
        {
            Directory.Delete(Application.temporaryCachePath, true);
        }

        public class OpenPath
        {
            [MenuItem(Editor_Scene.cTools + "/打开路径/沙盒 persistentDataPath", false, 10)]
            static void OpenPersistentPath()
            {
                EditorUtility.RevealInFinder(Application.persistentDataPath);
            }

            [MenuItem(Editor_Scene.cTools + "/打开路径/缓存 temporaryCachePath", false, 15)]
            static void OpenPersistentPathss()
            {
                EditorUtility.RevealInFinder(Application.temporaryCachePath);
            }

            [MenuItem(Editor_Scene.cTools + "/打开路径/ WebServer", false, 18)]
            static void OpenTempD()
            {
                string userDataDir = null;
                #if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
                userDataDir = "C:/inetpub/wwwroot";
                #else
                userDataDir = "/Library/WebServer/Documents";
                #endif
                userDataDir = "/Library/WebServer/Documents";
                EditorUtility.RevealInFinder(userDataDir);
            }

            [MenuItem(Editor_Scene.cTools + "/打开路径/ 桌面", false, 20)]
            static void OpenTempDeee()
            {
                var userDataDir = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
                EditorUtility.RevealInFinder(userDataDir);
            }

            [MenuItem(Editor_Scene.cTools + "/打开路径/ 我的文档", false, 20)]
            static void OpenTempMyDoc()
            {
                var userDataDir = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
                EditorUtility.RevealInFinder(userDataDir);
            }

            [MenuItem(Editor_Scene.cTools + "/打开路径/ _APIRequest_jsonData 路径", false, 18)]
            static void OpenTempD22()
            {
                string userDataDir = Application.dataPath + "/../Library/logList/currLogList/_APIRequest_jsonData";
                userDataDir = new DirectoryInfo(userDataDir).FullName;
                EditorUtility.RevealInFinder(userDataDir);
            }
        }
        public class RunInBackground
        {
            [MenuItem(Editor_Scene.cTools + "/U3dCore/编辑器是否允许 后台运行/true", false, 15)]
            static void OpenPersistentPathss()
            {
                PlayerSettings.runInBackground = true;
            }

            [MenuItem(Editor_Scene.cTools + "/U3dCore/编辑器是否允许 后台运行/false", false, 30)]
            static void OpenPersistentPathss3232()
            {
                PlayerSettings.runInBackground = false;
            }
        }

        [MenuItem(Editor_Scene.cTools + "/打开LogList")]
        static void __OpenLogww()
        {
            //Editor_GameViewSize.SetScreenSize();
            var dir = Application.dataPath + "/../Library/logList/currLogList";
            dir = new DirectoryInfo(dir).FullName;
            if (Directory.Exists(dir) == false)
            {
                dir = Application.dataPath + "/../Library/logList";
                dir = new DirectoryInfo(dir).FullName;
            }
            _OpenLog(dir);
        }

        static void _OpenLog(string path)
        {
            const string localEnd = "-local.html";
            FileInfo[] fileInfoArr = new DirectoryInfo(path).GetFiles("*.html", SearchOption.AllDirectories);
            var len = fileInfoArr.Length;
            if (len > 0)
            {
                fileInfoArr = fileInfoArr.OrderByDescending(n => n.LastWriteTime).ToArray();
                var fullPath = fileInfoArr[0].FullName;
                if (fullPath.EndsWith(localEnd))
                {
                    var time0 = fileInfoArr[0].LastWriteTime.ToFileTime() * 0.000001;
                    var time1 = fileInfoArr[1].LastWriteTime.ToFileTime() * 0.000001;
                    if (time1 + 5 > time0)
                    {
                        fullPath = fileInfoArr[1].FullName;
                    }
                    Debug.LogError($"打开文件时间.......{time0}/{time1}");
                }
                EditorUtility.RevealInFinder(fullPath);
                #if UNITY_EDITOR_WIN
                Process.Start($"{fullPath}");
                #else
                Process.Start($"/Applications/Google Chrome.app", fullPath);
                #endif
            } else
            {
                EditorUtility.DisplayDialog("没有log文件", "无法打开......", "知道了");
            }
        }
    }
    public static class Editor_Scene
    {
        public const string cTools = "Tools/CTools";
    }
}

#endif
